
package com.compuvest.web;

public class ItemsInBasket extends Item implements java.io.Serializable {

    public static final String PROMOSTRING = "<div style='color:blue;'><hr/>Original price $%.2f<br/>Promotion price $%,.2f you save <font color='red'>%,.2f%%.</font></div>";
    public static final String PROMOFORMAIL = "Original price $%.2f; Promotion price $%,.2f you save %,.2f%%.";

    private int totalQuantity;
    private boolean reseller = false;
    private double warranty;
    private String warrantyDesc = "";

    public ItemsInBasket() {
        this(new Item(), false);
    }

    public ItemsInBasket(final Item item, final boolean reseller) {

        this.setItemID(item.getItemID());
        this.setCategoryID(item.getCategoryID());
        this.setVendorID(item.getVendorID());
        this.setCategoryName(item.getCategoryName());
        this.setItemName(item.getItemName());
        this.setAccwareCode(item.getAccwareCode());
        this.setUPC(item.getUPC());

        this.setPrice(item.getPrice());
        this.setCostPrice(item.getCostPrice());
        this.setPromotionCode(item.getPromotionCode());
        this.setPromoCode(item.getPromoCode());

        this.setResPrice1(item.getResPrice1());
        this.setResPrice2(item.getResPrice2());
        this.setResQuantity2(item.getResQuantity2());
        this.setResPrice3(item.getResPrice3());
        this.setResQuantity3(item.getResQuantity3());

        this.setQuantity(item.getQuantity());
        this.setWeight(item.getWeight());
        this.setStock(item.getStock());
        this.setMfrName(item.getMfrName());
        this.setMfrNumber(item.getMfrNumber());
        this.setCondition(item.getCondition());
        this.setPackage(item.getPackage());

        this.setWarrantyMask(item.getWarrantyMask());
        this.setWarrantyPrice1(item.getWarrantyPrice1());
        this.setWarrantyPrice2(item.getWarrantyPrice2());
        this.setWarrantyPrice3(item.getWarrantyPrice3());

        this.totalQuantity = 1;
        this.reseller = reseller;
    }

    public int getTotalQuantity()                       { return totalQuantity; }
    public void setTotalQuantity(int totalQuantity)	{ this.totalQuantity = totalQuantity; }

    public double getWarrantyPrice()                    { return warranty; }
    public void setWarrantyPrice(double warranty)	{ this.warranty = warranty; }

    public String getWarrantyDesc()                     { return warrantyDesc; }
    public void setWarrantyDesc(String warrantyDesc)	{ this.warrantyDesc = warrantyDesc; }

    public double getWarrantyTotal()                    { return warranty * totalQuantity; }

    public boolean getReseller()                        { return reseller; }

// <editor-fold defaultstate="collapsed" desc="getPromotionPriceString()">

    public String getPromotionPriceString(boolean isMail) {

        if(getPromoProcent() == 0d) return "";

        return String.format(isMail ? PROMOFORMAIL : PROMOSTRING, getPrice(), getSellPrice(), getPromoProcent());
    }
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc="getSellPrice()">

    public double getSellPrice() {

        double sellPrice = getPrice();

        if(getReseller() && getResPrice1() != 0d) {

            if(getResQuantity3() != 0 && getTotalQuantity() > getResQuantity3() && getResPrice3() != 0d) {
                sellPrice = getResPrice3();
            }
            else if(getResQuantity2() != 0 && getTotalQuantity() > getResQuantity2() && getResPrice2() != 0d) {
                sellPrice = getResPrice2();
            }
            else {
                sellPrice = getResPrice1();
            }
        }
        else if(getPromoProcent() != 0d) {
            sellPrice = getPrice() - ((getPrice() * (getPromoProcent() / 100d)));
        }

        return sellPrice;
    }
// </editor-fold>
}
